import axios from "../util/axios";

// 创建订单
export function createOrder(params) {
  return axios.post("/saveOrder", params, {
    headers: {
      token: localStorage.getItem("token") || "",
    },
  });
}

// 获取订单列表
export function getOrderList(params) {
  return axios.get("/order", {
    params,
    headers: {
      token: localStorage.getItem("token") || "",
    },
  });
}

export function getOrderDetail(id) {
  return axios.get(`/order/${id}`, {
    headers: {
      token: localStorage.getItem("token") || "",
    },
  });
}

export function cancelOrder(id) {
  return axios.put(
    `/order/${id}/cancel`,
    {},
    {
      headers: {
        token: localStorage.getItem("token") || "",
      },
    }
  );
}

export function confirmOrder(id) {
  return axios.put(
    `/order/${id}/finish`,
    {},
    {
      headers: {
        token: localStorage.getItem("token") || "",
      },
    }
  );
}

export function payOrder(params) {
  return axios.get("/paySuccess", {
    params,
    headers: {
      token: localStorage.getItem("token") || "",
    },
  });
}
